#!/usr/bin/env ruby

# Define a class for our repeated and convenient use
class DNAseq
  # Declare a property (or "attribute" that is get-able and set-able from outside the object)
  attr_accessor :seq

  # Constructor...called automatically when new() is called
  def initialize(sequence='')
    @seq = sequence
  end

  # Method to calculate Tm, melting temperature (short oligos, very rough est. and assumptions)
  def meltingTemp(celcius=true)
    gc = gcCount()
    at = @seq.count("atAT")
    tm = 4 * gc + 2 * at
    unless(celcius)
      tm = (9.0/5) * tm + 32
    end
    return tm
  end

  # Method to tell us number of GCs
  def gcCount()
    return seq.count("gcGC")
  end
end



# Example usage:
# create some DNAseq objects
dna1 = DNAseq.new("aattggcc")
dna2 = DNAseq.new("atgggcCCgcAga")
# Use dna1 and ask it questions
puts "DNA1 has sequence '#{dna1.seq}' with #{dna1.gcCount()} GCs and a est Tm of #{dna1.meltingTemp()}C"

# Retrieve info from dna2 for use later
gcCount2 = dna2.gcCount()
tm2 = dna2.meltingTemp(false)
# later use
puts "DNA2 has sequence '#{dna2.seq}' with #{gcCount2} GCs and a est Tm of #{tm2}F"

# set the seq attribute of dna1 to a new value
dna1.seq = "gcgcgcgcgcgcggg"
puts "Updated DNA1 has sequence '#{dna1.seq}' with #{dna1.gcCount()} GCs and a est Tm of #{dna1.meltingTemp()}C"

